<template>
  <div class="center">
    <!-- 添加售后start -->
    <fill v-if="fillShow" @closeFill="closeFill" />
    <!-- 添加售后end -->

    <!-- 售后进度start -->
    <schedule v-else-if="scheduleShow" @closeSchedule="closeSchedule" :scheduleId="scheduleId" />
    <!-- 售后进度end -->

    <div v-else>
      <!-- 头部 -->
      <div class="table_header flex flex_bet flex-wrap">
        <div class="table_button">
          <el-button type="primary" icon="el-icon-refresh" size="mini" @click="Refresh"></el-button>
          <el-button type="primary" icon="el-icon-plus" size="mini" @click="gotoFill">售后申请</el-button>
        </div>
        <div class="table_searchs flex felx_align">
          <div class="table_search flex">
            <el-input placeholder="搜索" v-model="searchTable" class="input-with-select" size="small">
              <el-select v-model="select" slot="prepend" placeholder="请选择" class="table_select" style="width:105px">
                <el-option label="订单号" value="1"></el-option>
                <el-option label="设备码" value="2"></el-option>
                <el-option label="用户编号" value="3"></el-option>
              </el-select>
              <el-button slot="append" icon="el-icon-search" @click="idnameSearch"></el-button>
            </el-input>
          </div>
          <dynamicTable :checkboxVal="checkboxVal" @alter="alterCheckbok" />
        </div>
      </div>
      <!-- 专题管理table -->
      <el-table stripe :data="brandTable" style="width: 100%" :key="key" border fit highlight-current-row ref="tableDataRef">
        <el-table-column v-if="colData[0].istrue" prop="order_no" label="申请单号" min-width="160" align="center"></el-table-column>
        <el-table-column v-if="colData[1].istrue" prop="apply_time" label="申请日期" min-width="140" align="center">
          <template slot-scope="scope">{{scope.row.apply_time| newDate}}</template>
        </el-table-column>
        <el-table-column v-if="colData[2].istrue" prop="product_model" label="产品型号" min-width="140" align="center"></el-table-column>
        <el-table-column v-if="colData[3].istrue" prop="fault_type" label="故障类别" min-width="80" align="center">
          <template slot-scope="scope">
            {{scope.row.fault_type == 1 ? '显示异常' : scope.row.fault_type == 2 ? '触摸异常' : scope.row.fault_type == 3 ? '充电异常' : scope.row.fault_type == 4 ? '摄像头异常' :
              scope.row.fault_type == 5 ? '喇叭异常' : scope.row.fault_type == 6 ? '耳机异常' : scope.row.fault_type == 7 ? '卡开机画面' : scope.row.fault_type == 8 ? '无法开机' :
              scope.row.fault_type == 9 ? '客户误判' : '其他'}}
          </template>
        </el-table-column>
        <el-table-column v-if="colData[4].istrue" prop="fault_remark" label="故障描述" min-width="170" align="center"></el-table-column>
        <el-table-column v-if="colData[5].istrue" prop="is_analyse" label="是否需分析报告" min-width="120" align="center">
          <template slot-scope="scope">
            {{scope.row.is_analyse == 1 ? '是' : '否'}}
          </template>
        </el-table-column>
        <el-table-column v-if="colData[6].istrue" prop="mail_express" label="寄出快递" min-width="90" align="center"></el-table-column>
        <el-table-column v-if="colData[7].istrue" prop="mail_order_no" label="寄出单号" min-width="160" align="center"></el-table-column>
        <el-table-column v-if="colData[8].istrue" label="受理状态" min-width="90" align="center">
          <template slot-scope="scope">{{scope.row.accept_type == 1 ? '待受理' : scope.row.accept_type == 2 ? '已受理' : '已完成' }}</template>
        </el-table-column>
        <el-table-column v-if="colData[9].istrue" prop="accept_remark" label="受理备注信息" min-width="120" align="center"></el-table-column>
        <el-table-column v-if="colData[10].istrue" label="售后类型" min-width="90" align="center">
          <template slot-scope="scope">{{scope.row.after_type == 1 ? '退货' : scope.row.after_type == 2 ? '换新' : scope.row.after_type == 3 ? '换良品' : scope.row.after_type == 4 ? '保内维修' :
            scope.row.after_type == 5 ? '保外维修' : scope.row.after_type == 6 ? '原反' : '报废' }}</template>
        </el-table-column>
        <el-table-column v-if="colData[11].istrue" label="现象复判" min-width="90" align="center">
          <template slot-scope="scope">{{scope.row.phenomenon == 1 ? '显示异常' : scope.row.phenomenon == 2 ? '触摸异常' : scope.row.phenomenon == 3 ? '充电异常' : scope.row.phenomenon == 4 ? '摄像头异常' :
            scope.row.phenomenon == 5 ? '喇叭异常' : scope.row.phenomenon == 6 ? '耳机异常' : scope.row.phenomenon == 7 ? '开机画面卡' : scope.row.phenomenon == 8 ? '无法开机':
            scope.row.phenomenon == 9 ? '客户误判' : '其他' }}</template>
        </el-table-column>
        <el-table-column v-if="colData[12].istrue" prop="phenomenon_remark" label="现象描述" min-width="140" align="center"></el-table-column>
        <el-table-column v-if="colData[13].istrue" label="分析报告地址" min-width="120" align="center">
          <template slot-scope="scope">
            <div class="flex flex_cen felx_align">
              <i class="iconfont iconanzhuo download" style="border:none;background-color:inherit;color:#a4c872"><a target="_blank" :href="scope.row.analysis_report"></a> </i>
            </div>
          </template>
        </el-table-column>
        <el-table-column v-if="colData[14].istrue" label="处理状态" min-width="80" align="center">
          <template slot-scope="scope">{{scope.row.handle_type == 1 ? '未收货' : scope.row.handle_type == 2 ? '待处理' : scope.row.handle_type == 3 ? '维修中' : 
            scope.row.handle_type == 4 ? '待返还' : '已返还' }}</template>
        </el-table-column>
        <el-table-column v-if="colData[15].istrue" prop="return_time" label="返还日期" min-width="140" align="center">
          <template slot-scope="scope">{{scope.row.return_time| newDate}}</template>
        </el-table-column>
        <el-table-column v-if="colData[16].istrue" prop="return_express" label="返还快递" min-width="80" align="center"></el-table-column>
        <el-table-column v-if="colData[17].istrue" prop="return_express_order" label="返款单号" min-width="160" align="center"></el-table-column>
        <el-table-column label="操作" min-width="160" align="center">
          <template slot-scope="scope">
            <el-row>
              <el-button type="primary" size="mini" @click.stop="openSchedule(scope.row.id)">详情</el-button>
            </el-row>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="paging">
        <el-pagination :current-page.sync="listQuery.startSize" :page-sizes="[10, 50, 100, 200]" :page-size="listQuery.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total" background @size-change="handleSizeChange" @current-change="handleCurrentChange"></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import dynamicTable from "@/components/DynamicTable";
import objectable from "@/utils/objectable.js";
import { queryCustomerAfterSales } from "@/api/aftersale.js";
import fill from '../components/fill.vue'
import schedule from '../components/schedule.vue'
export default {
  components: { dynamicTable, fill, schedule },
  data() {
    return {
      checkboxVal: ['申请单号', '申请日期', '产品型号', '故障类别', '故障描述', '是否需分析报告', '寄出快递', '寄出单号', '受理状态', '受理备注信息', '售后类型',
        '现象复判', '现象描述', '分析报告', '处理状态', '返还日期', '返还快递', '返款单号'],
      key: 1,
      colData: [],//动态控制table
      brandTable: [],
      select: "", //搜索条件
      searchTable: "",
      total: 0, //总数量
      listQuery: { startSize: 1, pageSize: 10, orderNo: undefined, sn: undefined, userId: localStorage.getItem("ID") },
      fillShow: false,
      scheduleShow: false,
      scheduleId: 0
    }
  },
  created() {
    this.colData = objectable(this.checkboxVal, this.checkboxVal);//转为数组对象，好控制table
    this.getqueryCustomerAfterSales()
  },
  methods: {
    //详情
    closeSchedule() {
      this.scheduleShow = false
    },
    openSchedule(id) {
      this.scheduleId = id
      this.scheduleShow = true
    },
    //添加售后
    gotoFill() {
      this.fillShow = true
    },
    closeFill() {
      this.fillShow = false
      this.getqueryCustomerAfterSales()
    },
    getqueryCustomerAfterSales() {
      queryCustomerAfterSales(this.listQuery).then(res => {
        this.brandTable = res.data
        this.total = res.total
      }).catch(err => {
        this.brandTable = []
        this.total = 0
      })
    },
    //分页
    handleSizeChange(val) {
      this.listQuery.pageSize = val
      this.getqueryCustomerAfterSales();
    },
    handleCurrentChange(val) {
      this.listQuery.startSize = val
      this.getqueryCustomerAfterSales();
    },
    //搜索,1，专题名称
    idnameSearch() {
      if (!this.select) return this.$message.warning("请先选择查询条件");
      this.listQuery.startSize = 1
      this.listQuery.pageSize = 10
      switch (this.select) {
        case '1':
          this.listQuery.orderNo = this.searchTable
          break;
        case '2':
          this.listQuery.sn = this.searchTable
          break;
        case '3':
          this.listQuery.userId = this.searchTable
          break;
      }
      this.getqueryCustomerAfterSales();
    },
    Refresh() {
      this.listQuery = { startSize: 1, pageSize: 10, orderNo: undefined, sn: undefined, userId: localStorage.getItem("ID") }
      this.getqueryCustomerAfterSales()
    },
    //下拉动态table子组件
    alterCheckbok(key, conte) {
      this.key = key;
      this.colData.filter(i => {
        if (conte.indexOf(i.title) != -1) {
          i.istrue = false;
          this.$nextTick(() => {
            this.$refs.tableDataRef.doLayout();
          });
        } else {
          i.istrue = true;
          this.$nextTick(() => {
            this.$refs.tableDataRef.doLayout();
          });
        }
      });
    }
  }
}
</script>